﻿using System.Collections.Generic;
using System.Threading.Tasks;

namespace WeiboWPSdk.Api {
    public class CommonApi : ApiBase {
        public CommonApi(ClientHttpHelper httpHelper)
            : base(httpHelper) {
        }

        #region 读取接口
        /// <summary>
        /// 通过地址编码获取地址名称
        /// http://open.weibo.com/wiki/2/common/code_to_location
        /// </summary>
        /// <param name="codes">需要查询的地址编码，多个之间用逗号分隔。</param>
        /// <returns></returns>
        public async Task<IDictionary<string, string>> CodeToLocationAsync(params string[] codes) {
            var json = await HttpHelper.GetBasicCommandAsync("common/code_to_location", new WeiboParameter("codes", string.Join(",", codes)));
            return Utility.GetDictionaryFromJson(json);
        }
        /// <summary>
        /// 获取城市列表
        /// http://open.weibo.com/wiki/2/common/get_city
        /// </summary>
        /// <param name="province">省份的省份代码。</param>
        /// <param name="capital">城市的首字母，a-z，可为空代表返回全部，默认为全部。</param>
        /// <param name="language">返回的语言版本，zh-cn：简体中文、zh-tw：繁体中文、english：英文，默认为zh-cn。</param>
        /// <returns></returns>
        public async Task<IDictionary<string, string>> GetCityAsync(string province, string capital = null, string language = "zh-cn") {
            var json = await HttpHelper.GetBasicCommandAsync("common/get_city", new WeiboParameter("province", province), new WeiboParameter("capital", capital),
                new WeiboParameter("language", language));
            return Utility.GetDictionaryFromJson(json);
        }
        /// <summary>
        /// 获取省份列表
        /// http://open.weibo.com/wiki/2/common/get_province
        /// </summary>
        /// <param name="country">国家的国家代码。</param>
        /// <param name="capital">省份的首字母，a-z，可为空代表返回全部，默认为全部。</param>
        /// <param name="language">返回的语言版本，zh-cn：简体中文、zh-tw：繁体中文、english：英文，默认为zh-cn。</param>
        /// <returns></returns>
        public async Task<IDictionary<string, string>> GetProvinceAsync(string country, string capital = null, string language = "zh-cn") {
            var json = await HttpHelper.GetBasicCommandAsync("common/get_province", new WeiboParameter("country", country), new WeiboParameter("capital", capital),
                new WeiboParameter("language", language));
            return Utility.GetDictionaryFromJson(json);
        }
        /// <summary>
        /// 获取国家列表
        /// http://open.weibo.com/wiki/2/common/get_country
        /// </summary>
        /// <param name="capital">国家的首字母，a-z，可为空代表返回全部，默认为全部。</param>
        /// <param name="language">返回的语言版本，zh-cn：简体中文、zh-tw：繁体中文、english：英文，默认为zh-cn。</param>
        /// <returns></returns>
        public async Task<IDictionary<string, string>> GetCountryAsync(string capital = null, string language = "zh-cn") {
            var json = await HttpHelper.GetBasicCommandAsync("common/get_country", new WeiboParameter("capital", capital), new WeiboParameter("language", language));
            return Utility.GetDictionaryFromJson(json);
        }
        /// <summary>
        /// 获取时区配置表
        /// http://open.weibo.com/wiki/2/common/get_timezone
        /// </summary>
        /// <param name="language">返回的语言版本，zh-cn：简体中文、zh-tw：繁体中文、english：英文，默认为zh-cn。</param>
        /// <returns></returns>
        public async Task<IDictionary<string, string>> GetTimezoneAsync(string language = "zh-cn") {
            var json = await HttpHelper.GetBasicCommandAsync("common/get_timezone", new WeiboParameter("language", language));
            return Utility.GetDictionaryFromJson(json);
        }
        #endregion
    }
}
